package file;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

public class FileCreate {


    public static void main(String[] args) {

        FileCreate fileCreate = new FileCreate();
        fileCreate.createFile1();
        fileCreate.createFile2();
        fileCreate.createFile3();


    }

    //使用file类的构造器创建文件

    @Test
    public void createFile1() {

        //File(String pathname)
        String filePath = "D:\\aaaa\\test.txt";
        File file = new File(filePath);
        try {
            //创建文件
            file.createNewFile();
            System.out.println("文件test创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void createFile2() {

        // File(String parent, String child) 父目录路径，子路径
        File file = new File("D:\\aaaa", "test2.txt");
        try {
            //创建文件
            file.createNewFile();
            System.out.println("文件test2创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @Test
    public void createFile3() {

        // File(File parent, String child) 父文件对象，子路径
        File parent = new File("D:\\aaaa");
        String fileName = "test3.txt";
        File file = new File(parent, fileName);
        try {
            //创建文件
            file.createNewFile();
            System.out.println("文件test3创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}